﻿using AntdUI;
using BST250301;
using BST250301TestStand.Models;
using BST250301TestStand.Models.Utils;
using Microsoft.Identity.Client;
using MySql.Data.MySqlClient;
using NPOI.Util;
using System.Diagnostics;
using System.Threading.Tasks;
using static BST250301TestStand.Models.Utils.TCUConfig;
using static System.ComponentModel.Design.ObjectSelectorEditor;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace BST250301.Views
{
    public partial class PlanSelect : UserControl
    {
        public static event EventHandler<string> PlanChanged;

        public PlanSelect()
        {
            InitializeComponent();
            InitTableColumns();
            InitData();
        }
        private void InitTableColumns()
        {
            table_base.Columns = new ColumnCollection() {
                new AntdUI.Column("OrderID", "记录序号",ColumnAlign.Center),
                new AntdUI.Column("TestName", "模板名称",ColumnAlign.Center),
                //new AntdUI.Column("Description", "模板描述",ColumnAlign.Center){Width ="200"},
                new AntdUI.Column("UserId", "建立用户",ColumnAlign.Center),
                new AntdUI.Column("DT", "建立日期",ColumnAlign.Center),                           
            };
        }

        private void InitData()
        {
            var result = DB.GetPlanName(MainWindow.configapp.DBConnectionServer);
            if (result != null)
            {
                selectPlanName.Items.Clear();
                foreach (var item in result)
                {
                    selectPlanName.Items.Add(item.PlanName);
                }
                selectPlanName.Items.Add("新建方案名");
            }
        }


        private void buttonADD_Click_1(object sender, EventArgs e)
        {
            PlanChanged?.Invoke(this, selectPlanName.Text);
        }

        private void selectPlanName_SelectedIndexChanged(object sender, IntEventArgs e)
        {
            GetAntduiList(selectPlanName.Text);
        }
        private async Task GetAntduiList(string selectname)
        {
            // AntList<TemplateItem>
            AntList<TemplateItem> plateList = DB.GetTestTemplate(selectname);
            table_base.Binding(plateList);
            table_base.Bordered = true;
        }
    }
}
